<?php

use yii\db\Migration;

class m171212_014549_alert_goods extends Migration
{
    private function createDbs(){
        $dbs = [];
        $dbs_info =\Yii::$app->params['db'];
        foreach($dbs_info as $k=>$v){
            $dbs[$k] = \Yii::createObject($v);
        }
        return $dbs;
    }
    public function safeUp()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->addColumn('{{%goods}}', 'status', $this->smallInteger(2)->defaultValue(0)->comment('状态（0未设置 1上架 2驳回 3待审核）'));
            $this->addColumn('{{%goods}}', 'auditing', $this->text()->defaultValue(null)->comment('审核意见'));
        }
    }

    public function safeDown()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->dropColumn('{{%goods}}', 'status');
            $this->dropColumn('{{%goods}}', 'auditing');
        }
    }
}
